package com.zwd.deep.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zwd.deep.entity.dto.MedicationDto;
import com.zwd.deep.entity.po.Medications;
import com.zwd.deep.entity.vo.MedicationVo;
import com.zwd.deep.mapper.MedicationsMapper;
import com.zwd.deep.service.IMedicationsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用药方案表 服务实现类
 * </p>
 *
 * @author zwd
 * @since 2025-02-12
 */
@Service
public class MedicationsServiceImpl extends ServiceImpl<MedicationsMapper, Medications> implements IMedicationsService {
    @Autowired
    private MedicationsMapper medicationsMapper;

    @Override
    public List<MedicationVo> getMedications(Integer diagnosisId) {
        List<Medications> medicationsList =  medicationsMapper.selectListByDiagnosisId(diagnosisId);
        ArrayList<MedicationVo> medicationVos = new ArrayList<>();
        medicationsList.forEach(medications -> {
            MedicationVo medicationVo = new MedicationVo();
            BeanUtil.copyProperties(medications, medicationVo);
            medicationVos.add(medicationVo);
        });
        return medicationVos;
    }

    @Override
    public String addMedication(List<MedicationDto> medicationDto) {
        for (MedicationDto dto : medicationDto) {
            Medications medication = new Medications();
            BeanUtil.copyProperties(dto, medication);
            medicationsMapper.insert(medication);
        }
        return "ok";
    }
}
